#ifndef LEETCODE_CN_CPP_PROBLEMS_442_H
#define LEETCODE_CN_CPP_PROBLEMS_442_H

#include <cmath>
#include <vector>

using namespace std;

namespace problem_442
{

class Solution
{
public:
    vector<int> findDuplicates(vector<int> &nums)
    {
        vector<int> dups;
        for (int i = 0; i < nums.size(); ++i)
        {
            int k = abs(nums[i]) - 1;
            if (nums[k] < 0)
                dups.push_back(abs(k + 1));
            nums[k] = -nums[k];
        }
        return move(dups);
    }
};

} // namespace problem_442

#endif //LEETCODE_CN_CPP_PROBLEMS_442_H
